package com.motherchild.user.controller;

import com.motherchild.common.ApiResponse;
import com.motherchild.user.dto.CartItemDTO;
import com.motherchild.user.dto.Password;
import com.motherchild.user.dto.User;
import com.motherchild.user.service.CartService;
import com.motherchild.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/info/{userId}")
    public ApiResponse<User> getUserInfo(@PathVariable Long userId) {
        User user = userService.getUserInfo(userId);
        return ApiResponse.success(user);
    }
    @PostMapping("/password/{userId}")
    public ApiResponse<Void> updatePassword(@RequestBody Password password, @PathVariable Long userId) {

        boolean isUpdated = userService.updatePassword(userId, password.getNewPassword());

            return ApiResponse.success();


        }




    @PutMapping("/info")
    public ApiResponse<User> updateUserInfo(@RequestBody User user) {
        userService.updateUserInfo(user);
        return ApiResponse.success(null);
    }


} 